﻿#include <iostream>
#include <thread>
//linux -- lpthread
using namespace std;

void myThread() {
	for (size_t i = 0; i < 10; i++)
	{
		cout << i + 1 << endl;
		this_thread::sleep_for(chrono::seconds(1));
	}

}

int main()
{
	cout << "join：阻塞等待子线程结束，导致主线程阻塞，等待子线程退出，这也不是我们想要的!" << endl;
	cout << "detach：子线程与主程序分离，变成了守护线程，与主线程无关，导致主线程退出后，子线程不一定退出!" << endl;
	cout << "mutex lock：获取锁资源，如果失败则阻塞等待!" << endl;
	cout << "mutex try_lock：尝试是否获取锁资源成功，可以循环不间断尝试，尝试是有资源消耗的!" << endl;
	cout << "mutex try_lock_for：超时锁，避免长时间死锁!" << endl;
	cout << "mutex unlock：释放锁!" << endl;
	thread th(myThread);
	th.join();
	cout << "OVER!" << endl;
}

